package com.bw.launcher.gateway

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.blankj.utilcode.util.LogUtils
import com.bw.launcher.R
import com.bw.launcher.gateway.entity.GatewayEntity
import com.bw.quickadapter.BaseQuickMultipleAdapter
import com.bw.quickadapter.BaseViewHolder

class GatewayAdapter : BaseQuickMultipleAdapter<GatewayEntity>() {

    override fun convert(holder: BaseViewHolder?, item: GatewayEntity?) {
        item!!.let {
            if (it.getType() == 100){
                holder!!.setText(R.id.gateway_title_title,it.title)
                holder!!.setImage(R.id.gateway_title_img,it.iconId)
            }else if (it.getType() == 200){
                holder!!.setImage(R.id.gateway_child_img,it.iconId)
                holder!!.setText(R.id.gateway_child_title,it.title)
            }
        }
    }

    override fun createItemVIew(viewType: Int, parent: ViewGroup?): View {
        return if (viewType == 100){
            LayoutInflater.from(parent!!.context).inflate(R.layout.item_gateway_title,parent,false)
        } else{
            LayoutInflater.from(parent!!.context).inflate(R.layout.item_gateway_child,parent,false)
        }
    }

    override fun getItemType(position: Int): Int {
        return data[position].getType()
    }
    //判断类型 占几份
    override fun getMultipleSpanSize(position: Int,recyclerView: RecyclerView): Int {
        val layoutmanager = recyclerView.layoutManager
        if (layoutmanager !is GridLayoutManager){
            return 1
        }
        if (data[position].getType() == 100)
            return 3
        return 1
    }
}